﻿
<ComponentsUserCard />
<MudNavMenu>
    <MudNavLink Href="/" Match="NavLinkMatch.All" Icon="@Icons.Material.Outlined.Dashboard">
        @DashboardResource.StringDashboard
    </MudNavLink>

    @if (AccountStateContainer.IdUserDepartments.Any())
    {
        @*<Maanfee.Dashboard.Messaging.Views._Sidebar />
    <Ashna.Attendance.Views._Sidebar />*@
    }

    @*<AuthorizeView Roles=@($"{SystemAccessDefaultValue.AccessDeveloper} {SystemAccessDefaultValue.AccessSupervisor} {SystemAccessDefaultValue.AccessAdmin}")>
    <Authorized>*@

    @*	<MudListSubheader Class="mt-2 mb-n2">
    @DashboardResource.StringCommunications
    </MudListSubheader>
    <MudNavGroup Title="@DashboardResource.StringCommunications" Icon="@Icons.Filled.Chat" ExpandIcon="@Icons.Material.Filled.ExpandMore">
    <MudNavLink Href="/chat">
    @DashboardResource.StringChat
    </MudNavLink>
    </MudNavGroup>*@

    @if (_PermissionDepartments || _PermissionRoles || _PermissionUsers || _PermissionGroups)
    {
        <MudListSubheader Class="mt-2 mb-n2">
            @DashboardResource.StringAdministrator
        </MudListSubheader>
        <MudNavGroup Title="@DashboardResource.StringUserManagement" Icon="@Icons.Material.Outlined.SupervisorAccount" ExpandIcon="@Icons.Material.Filled.ExpandMore">
            @if (_PermissionRoles)
            {
                <MudNavLink Href="/Roles/RoleView">
                    @DashboardResource.StringRole
                </MudNavLink>
            }
            @if (_PermissionDepartments)
            {
                <MudNavLink Href="/Departments/DepartmentView">
                    @DashboardResource.StringDepartment
                </MudNavLink>
            }
            @if (_PermissionGroups)
            {
                <MudNavLink Href="/Groups/GroupView">
                    @DashboardResource.StringGroup
                </MudNavLink>
            }
            @if (_PermissionUsers)
            {
                <MudNavLink Href="/Users/UserView">
                    @DashboardResource.StringUser
                </MudNavLink>
            }
        </MudNavGroup>
    }

    @if (_PermissionReleaseManagement || _PermissionMonitoringLogs)
    {
        <MudNavGroup Title="@DashboardResource.StringSettings" Icon="@Icons.Material.Filled.Handyman" ExpandIcon="@Icons.Material.Filled.ExpandMore">
            @if (_PermissionReleaseManagement)
            {
                <MudNavLink Href="/Releases/SysReleaseMgtView">
                    @DashboardResource.StringRelease
                </MudNavLink>
            }
            @if (_PermissionMonitoringLogs)
            {
                <MudNavLink Href="/Settings/MonitoringLogsView">
                    @DashboardResource.StringMonitoringLogs
                </MudNavLink>
            }
        </MudNavGroup>
    }

    <MudNavGroup Title="@DashboardResource.StringAbout" Icon="@Icons.Material.Filled.Feed" ExpandIcon="@Icons.Material.Filled.ExpandMore">
        @if (_PermissionReleaseManagement)
        {
            <MudNavLink Href="/Releases/ReleaseView">
                @DashboardResource.StringRelease
            </MudNavLink>
        }
        @if (_PermissionPublicSwagger)
        {
            <MudNavLink Href="/swagger/index.html" Target="_blank">
                @DashboardResource.StringSwagger
            </MudNavLink>
        }
    </MudNavGroup>

    <Maanfee.Dashboard.Examples.Views._Sidebar />
    <Maanfee.Dashboard.Examples.Views.JsInterop._Sidebar />

</MudNavMenu>

@code {

    [CascadingParameter]
    private Task<AuthenticationState> PermissionAuthenticationState { get; set; }

    private bool _PermissionRoles = false;
    private bool _PermissionDepartments = false;
    private bool _PermissionGroups = false;
    private bool _PermissionUsers = false;
    private bool _PermissionPublicSwagger = false;
    private bool _PermissionReleaseManagement = false;
    private bool _PermissionMonitoringLogs = false;

    protected override async Task OnParametersSetAsync()
    {
        var PermissionCurrentUser = (await PermissionAuthenticationState).User;

        _PermissionRoles = (await AuthorizationService.AuthorizeAsync(PermissionCurrentUser, PermissionDefaultValue.Role.View)).Succeeded;
        _PermissionDepartments = (await AuthorizationService.AuthorizeAsync(PermissionCurrentUser, PermissionDefaultValue.Department.View)).Succeeded;
        _PermissionGroups = (await AuthorizationService.AuthorizeAsync(PermissionCurrentUser, PermissionDefaultValue.Group.View)).Succeeded;
        _PermissionUsers = (await AuthorizationService.AuthorizeAsync(PermissionCurrentUser, PermissionDefaultValue.User.View)).Succeeded;
        _PermissionPublicSwagger = (await AuthorizationService.AuthorizeAsync(PermissionCurrentUser, PermissionDefaultValue.Setting.Swagger)).Succeeded;
        _PermissionReleaseManagement = (await AuthorizationService.AuthorizeAsync(PermissionCurrentUser, PermissionDefaultValue.Setting.ReleaseManagementView)).Succeeded;
        _PermissionMonitoringLogs = (await AuthorizationService.AuthorizeAsync(PermissionCurrentUser, PermissionDefaultValue.Setting.MonitorLogs)).Succeeded;
    }

}
